﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace BanditGame2
{
    public partial class LoginScreen : UserControl
    {
        public LoginScreen()
        {
            InitializeComponent();
        }

        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            busyIndicator.IsBusy = true;
            WCFService.WCFServiceClient LAPClient = new WCFService.WCFServiceClient();
            LAPClient.getLoginMatchCompleted += new EventHandler<WCFService.getLoginMatchCompletedEventArgs>(LoginAccess_GetValidUser);
            LAPClient.getLoginMatchAsync(txtUsername.Text, txtPassword.Password);
        }

        private void LoginAccess_GetValidUser(object sender, WCFService.getLoginMatchCompletedEventArgs e)
        {
            busyIndicator.IsBusy = false;
            validationSummary.Errors.Clear();
            if (e.Result == 1)
            {
                PageSwitcher pageSwticher = (PageSwitcher)this.Parent;
                App.currentUserLogin = txtUsername.Text;
                pageSwticher.Navigate(new Menu());
            }
            else if (e.Result == 10)
            {
                validationSummary.Errors.Add(new ValidationSummaryItem("Chyba ve spojení s databází. Prosím kontaktujte administrátora."));
            }
            else
            {
                validationSummary.Errors.Add(new ValidationSummaryItem("Špatné uživatelské jméno nebo heslo."));
            }

        }

        private void btnSignUp_Click(object sender, RoutedEventArgs e)
        {
            SignUpWindow signUpWindow = new SignUpWindow();
            signUpWindow.Show();
        }
    }
}
